﻿<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:uc="clr-namespace:SqlMiM.Common.UserControls;assembly=SqlMiM.Common"             
    xmlns:conv="clr-namespace:SqlMiM.Common.Converters;assembly=SqlMiM.Common"
    xmlns:vsm="clr-namespace:System.Windows;assembly=WPFToolkit" 
    xmlns:local="clr-namespace:SqlMiM.SqlServer.SpaceUsage"
    xmlns:viewModel="clr-namespace:SqlMiM.SqlServer.ViewModel"
    xmlns:src="clr-namespace:SqlMiM.Common.Controls;assembly=SqlMiM.Common"
    xmlns:charting="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"    
    xmlns:datavis="clr-namespace:System.Windows.Controls.DataVisualization;assembly=System.Windows.Controls.DataVisualization.Toolkit"
    xmlns:chartingprimitives="clr-namespace:System.Windows.Controls.DataVisualization.Charting.Primitives;assembly=System.Windows.Controls.DataVisualization.Toolkit"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"    
    x:Class="SqlMiM.SqlServer.SpaceUsage.View"
    Loaded="UserControl_Loaded"
    mc:Ignorable="d"
    >


    <UserControl.Resources>


        <ResourceDictionary>


            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/SqlMiM.Common;component/Resources/ControlsTheme.xaml"/>

            </ResourceDictionary.MergedDictionaries>

            <conv:BooleanToVisibilityConverter x:Key="VisibleIfTrue" Inverted="True" Not="False"    />
            <conv:BooleanToVisibilityConverter x:Key="VisibleIfNotTrue" Inverted="True" Not="True"    />
            <conv:ReverseBooleanConverter x:Key="ReverseBooleanConverter" />

            <!--  charting:Chart  -->
            <Style TargetType="charting:Chart" x:Key="ChartMimumStyle">
                <Setter Property="BorderBrush" Value="Black" />
                <Setter Property="BorderThickness" Value="1" />
                <Setter Property="IsTabStop" Value="False" />
                <Setter Property="SnapsToDevicePixels" Value="True" />
                <Setter Property="StylePalette">
                    <Setter.Value>
                        <datavis:StylePalette>
                            <!-- Indigo -->
                            <Style TargetType="Control">
                                <Setter Property="Background">
                                    <Setter.Value>
                                        <RadialGradientBrush>
                                            <RadialGradientBrush.RelativeTransform>
                                                <TransformGroup>
                                                    <ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="2.09" ScaleY="1.819" />
                                                    <TranslateTransform X="-0.425" Y="-0.486" />
                                                </TransformGroup>
                                            </RadialGradientBrush.RelativeTransform>
                                            <GradientStop Color="#FFA9A3BD" />
                                            <GradientStop Color="#FF382C6C" Offset="1" />
                                        </RadialGradientBrush>
                                    </Setter.Value>
                                </Setter>
                            </Style>
                            <!-- Magenta -->
                            <Style TargetType="Control">
                                <Setter Property="Background">
                                    <Setter.Value>
                                        <RadialGradientBrush>
                                            <RadialGradientBrush.RelativeTransform>
                                                <TransformGroup>
                                                    <ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="2.09" ScaleY="1.819" />
                                                    <TranslateTransform X="-0.425" Y="-0.486" />
                                                </TransformGroup>
                                            </RadialGradientBrush.RelativeTransform>
                                            <GradientStop Color="#FFB1A1B1" />
                                            <GradientStop Color="#FF50224F" Offset="1" />
                                        </RadialGradientBrush>
                                    </Setter.Value>
                                </Setter>
                            </Style>
                            <!--Red-->
                            <Style TargetType="Control">
                                <Setter Property="Background">
                                    <Setter.Value>
                                        <RadialGradientBrush>
                                            <RadialGradientBrush.RelativeTransform>
                                                <TransformGroup>
                                                    <ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="2.09" ScaleY="1.819" />
                                                    <TranslateTransform X="-0.425" Y="-0.486" />
                                                </TransformGroup>
                                            </RadialGradientBrush.RelativeTransform>
                                            <GradientStop Color="#FFFBB7B5" />
                                            <GradientStop Color="#FF702828" Offset="1" />
                                        </RadialGradientBrush>
                                    </Setter.Value>
                                </Setter>
                            </Style>
                            <!--Blue-->
                            <Style TargetType="Control">
                                <Setter Property="Background">
                                    <Setter.Value>
                                        <RadialGradientBrush>
                                            <RadialGradientBrush.RelativeTransform>
                                                <TransformGroup>
                                                    <ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="2.09" ScaleY="1.819" />
                                                    <TranslateTransform X="-0.425" Y="-0.486" />
                                                </TransformGroup>
                                            </RadialGradientBrush.RelativeTransform>
                                            <GradientStop Color="#FFB9D6F7" />
                                            <GradientStop Color="#FF284B70" Offset="1" />
                                        </RadialGradientBrush>
                                    </Setter.Value>
                                </Setter>
                            </Style>
                            <!-- ColorLight Green -->
                            <Style TargetType="Control">
                                <Setter Property="Background">
                                    <Setter.Value>
                                        <RadialGradientBrush>
                                            <RadialGradientBrush.RelativeTransform>
                                                <TransformGroup>
                                                    <ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="2.09" ScaleY="1.819" />
                                                    <TranslateTransform X="-0.425" Y="-0.486" />
                                                </TransformGroup>
                                            </RadialGradientBrush.RelativeTransform>
                                            <GradientStop Color="#FFB8C0AC" />
                                            <GradientStop Color="#FF5F7143" Offset="1" />
                                        </RadialGradientBrush>
                                    </Setter.Value>
                                </Setter>
                            </Style>
                            <!-- Yellow -->
                            <Style TargetType="Control">
                                <Setter Property="Background">
                                    <Setter.Value>
                                        <RadialGradientBrush>
                                            <RadialGradientBrush.RelativeTransform>
                                                <TransformGroup>
                                                    <ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="2.09" ScaleY="1.819" />
                                                    <TranslateTransform X="-0.425" Y="-0.486" />
                                                </TransformGroup>
                                            </RadialGradientBrush.RelativeTransform>
                                            <GradientStop Color="#FFFDE79C" />
                                            <GradientStop Color="#FFF6BC0C" Offset="1" />
                                        </RadialGradientBrush>
                                    </Setter.Value>
                                </Setter>
                            </Style>
                            <!-- ColorDark Green -->
                            <Style TargetType="Control">
                                <Setter Property="Background">
                                    <Setter.Value>
                                        <RadialGradientBrush>
                                            <RadialGradientBrush.RelativeTransform>
                                                <TransformGroup>
                                                    <ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="2.09" ScaleY="1.819" />
                                                    <TranslateTransform X="-0.425" Y="-0.486" />
                                                </TransformGroup>
                                            </RadialGradientBrush.RelativeTransform>
                                            <GradientStop Color="#FF9DC2B3" />
                                            <GradientStop Color="#FF1D7554" Offset="1" />
                                        </RadialGradientBrush>
                                    </Setter.Value>
                                </Setter>
                            </Style>
                            <!--Gray Shade-->
                            <Style TargetType="Control">
                                <Setter Property="Background">
                                    <Setter.Value>
                                        <RadialGradientBrush>
                                            <RadialGradientBrush.RelativeTransform>
                                                <TransformGroup>
                                                    <ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="2.09" ScaleY="1.819" />
                                                    <TranslateTransform X="-0.425" Y="-0.486" />
                                                </TransformGroup>
                                            </RadialGradientBrush.RelativeTransform>
                                            <GradientStop Color="#FFB5B5B5" />
                                            <GradientStop Color="#FF4C4C4C" Offset="1" />
                                        </RadialGradientBrush>
                                    </Setter.Value>
                                </Setter>
                            </Style>
                            <!--Blue-->
                            <Style TargetType="Control">
                                <Setter Property="Background">
                                    <Setter.Value>
                                        <RadialGradientBrush>
                                            <RadialGradientBrush.RelativeTransform>
                                                <TransformGroup>
                                                    <ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="2.09" ScaleY="1.819" />
                                                    <TranslateTransform X="-0.425" Y="-0.486" />
                                                </TransformGroup>
                                            </RadialGradientBrush.RelativeTransform>
                                            <GradientStop Color="#FF98C1DC" />
                                            <GradientStop Color="#FF0271AE" Offset="1" />
                                        </RadialGradientBrush>
                                    </Setter.Value>
                                </Setter>
                            </Style>
                            <!-- Brown -->
                            <Style TargetType="Control">
                                <Setter Property="Background">
                                    <Setter.Value>
                                        <RadialGradientBrush>
                                            <RadialGradientBrush.RelativeTransform>
                                                <TransformGroup>
                                                    <ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="2.09" ScaleY="1.819" />
                                                    <TranslateTransform X="-0.425" Y="-0.486" />
                                                </TransformGroup>
                                            </RadialGradientBrush.RelativeTransform>
                                            <GradientStop Color="#FFC1C0AE" />
                                            <GradientStop Color="#FF706E41" Offset="1" />
                                        </RadialGradientBrush>
                                    </Setter.Value>
                                </Setter>
                            </Style>
                            <!--Cyan-->
                            <Style TargetType="Control">
                                <Setter Property="Background">
                                    <Setter.Value>
                                        <RadialGradientBrush>
                                            <RadialGradientBrush.RelativeTransform>
                                                <TransformGroup>
                                                    <ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="2.09" ScaleY="1.819" />
                                                    <TranslateTransform X="-0.425" Y="-0.486" />
                                                </TransformGroup>
                                            </RadialGradientBrush.RelativeTransform>
                                            <GradientStop Color="#FFADBDC0" />
                                            <GradientStop Color="#FF446A73" Offset="1" />
                                        </RadialGradientBrush>
                                    </Setter.Value>
                                </Setter>
                            </Style>
                            <!-- Special Blue -->
                            <Style TargetType="Control">
                                <Setter Property="Background">
                                    <Setter.Value>
                                        <RadialGradientBrush>
                                            <RadialGradientBrush.RelativeTransform>
                                                <TransformGroup>
                                                    <ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="2.09" ScaleY="1.819" />
                                                    <TranslateTransform X="-0.425" Y="-0.486" />
                                                </TransformGroup>
                                            </RadialGradientBrush.RelativeTransform>
                                            <GradientStop Color="#FF2F8CE2" />
                                            <GradientStop Color="#FF0C3E69" Offset="1" />
                                        </RadialGradientBrush>
                                    </Setter.Value>
                                </Setter>
                            </Style>
                            <!--Gray Shade 2-->
                            <Style TargetType="Control">
                                <Setter Property="Background">
                                    <Setter.Value>
                                        <RadialGradientBrush>
                                            <RadialGradientBrush.RelativeTransform>
                                                <TransformGroup>
                                                    <ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="2.09" ScaleY="1.819" />
                                                    <TranslateTransform X="-0.425" Y="-0.486" />
                                                </TransformGroup>
                                            </RadialGradientBrush.RelativeTransform>
                                            <GradientStop Color="#FFDCDCDC" />
                                            <GradientStop Color="#FF757575" Offset="1" />
                                        </RadialGradientBrush>
                                    </Setter.Value>
                                </Setter>
                            </Style>
                            <!--Gray Shade 3-->
                            <Style TargetType="Control">
                                <Setter Property="Background">
                                    <Setter.Value>
                                        <RadialGradientBrush>
                                            <RadialGradientBrush.RelativeTransform>
                                                <TransformGroup>
                                                    <ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="2.09" ScaleY="1.819" />
                                                    <TranslateTransform X="-0.425" Y="-0.486" />
                                                </TransformGroup>
                                            </RadialGradientBrush.RelativeTransform>
                                            <GradientStop Color="#FFF4F4F4" />
                                            <GradientStop Color="#FFB7B7B7" Offset="1" />
                                        </RadialGradientBrush>
                                    </Setter.Value>
                                </Setter>
                            </Style>
                            <!--Gray Shade 4-->
                            <Style TargetType="Control">
                                <Setter Property="Background">
                                    <Setter.Value>
                                        <RadialGradientBrush>
                                            <RadialGradientBrush.RelativeTransform>
                                                <TransformGroup>
                                                    <ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="2.09" ScaleY="1.819" />
                                                    <TranslateTransform X="-0.425" Y="-0.486" />
                                                </TransformGroup>
                                            </RadialGradientBrush.RelativeTransform>
                                            <GradientStop Color="#FFF4F4F4" />
                                            <GradientStop Color="#FFA3A3A3" Offset="1" />
                                        </RadialGradientBrush>
                                    </Setter.Value>
                                </Setter>
                            </Style>
                        </datavis:StylePalette>
                    </Setter.Value>
                </Setter>
                <Setter Property="PlotAreaStyle">
                    <Setter.Value>
                        <Style TargetType="Grid">
                            <Setter Property="Background" Value="Transparent" >
                            </Setter>
                        </Style>
                    </Setter.Value>
                </Setter>
                <Setter Property="ChartAreaStyle">
                    <Setter.Value>
                        <Style TargetType="Panel">
                            <Setter Property="MinWidth" Value="100" />
                            <Setter Property="MinHeight" Value="100" />
                        </Style>
                    </Setter.Value>
                </Setter>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="charting:Chart">
                            <Grid >
                                <chartingprimitives:EdgePanel x:Name="ChartArea" Style="{TemplateBinding ChartAreaStyle}" >
                                    <Grid Canvas.ZIndex="-1" Style="{TemplateBinding PlotAreaStyle}" />
                                </chartingprimitives:EdgePanel>
                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>


            <DataTemplate DataType="{x:Type viewModel:FilesStatView}">

                <ContentControl Margin="10,10,10,0" VerticalAlignment="Top" MinWidth="250" Grid.Column="0" Foreground="{DynamicResource Foreground}"
                                TextElement.Foreground="{DynamicResource Foreground}" TextBlock.Foreground="{DynamicResource Foreground}" >
                    <ContentControl.Content>

                        <StackPanel Orientation="Vertical" >
                            <ContentControl Style="{DynamicResource TitleContentControlStyle}">
                                <ContentControl.Content>
                                    <StackPanel Orientation="Horizontal">
                                        <Image HorizontalAlignment="Left" Margin="8,0,0,0" VerticalAlignment="Center" Width="16" Height="16" 
                                                Source="..\Images\database_table.png" Stretch="Fill"/>
                                        <TextBlock HorizontalAlignment="Left" Margin="5,0,0,0" VerticalAlignment="Center" 
                                                   Foreground="{DynamicResource Foreground}" FontWeight="Bold"  Text="{Binding FilesStat.DatabaseName}" TextWrapping="Wrap"/>
                                    </StackPanel>
                                </ContentControl.Content>
                            </ContentControl>

                            <StackPanel Orientation="Horizontal" Grid.Row="1">

                                <charting:Chart Style="{StaticResource ChartMimumStyle}"
                                            Title="File Groups" Margin="8,0,0,0" VerticalAlignment="Center"
                                            HorizontalAlignment="Left">
                                    <charting:Chart.Series>
                                        <charting:PieSeries ItemsSource="{Binding ALLIOMO}"
                                                DependentValueBinding="{Binding Value}" IndependentValueBinding="{Binding Name}" />
                                    </charting:Chart.Series>
                                </charting:Chart>

                                <UniformGrid  Columns="2"  Rows="2" Margin="10,5,0,0">
                                    <TextBlock Text="Total reads (Mo) :" />
                                    <TextBlock FontWeight="Bold" HorizontalAlignment="Right" Text="{Binding FilesStat.ReadsMo, StringFormat={}{0:0.##} Mo}" />

                                    <TextBlock  Text="Total writes (Mo) :" />
                                    <TextBlock  FontWeight="Bold" HorizontalAlignment="Right" 
                                       Text="{Binding FilesStat.WritesMo, StringFormat={}{0:0.##} Mo}" />
                                </UniformGrid>

                                <charting:Chart Style="{StaticResource ChartMimumStyle}"
                            Title="File Groups" Margin="8,0,0,0" VerticalAlignment="Center"
                            HorizontalAlignment="Left">
                                    <charting:Chart.Series>
                                        <charting:PieSeries ItemsSource="{Binding ALLIO}"
                                                DependentValueBinding="{Binding Value}" IndependentValueBinding="{Binding Name}" />
                                    </charting:Chart.Series>
                                </charting:Chart>

                                <UniformGrid  Columns="2"  Rows="2" Margin="10,5,0,0">

                                    <TextBlock  Text="Total reads :" />
                                    <TextBlock  FontWeight="Bold" HorizontalAlignment="Right" 
                                       Text="{Binding FilesStat.Reads, StringFormat={}{0:0.##}}" />

                                    <TextBlock  Text="Total writes :" />
                                    <TextBlock  FontWeight="Bold" HorizontalAlignment="Right" 
                                       Text="{Binding FilesStat.Writes, StringFormat={}{0:0.##}}" />
                                </UniformGrid>




                            </StackPanel>

                        </StackPanel>
                    </ContentControl.Content>
                </ContentControl>



            </DataTemplate>


            <Style  TargetType="{x:Type ListBoxItem}" x:Key="ListBoxItemStyle">
                <Setter Property="Cursor" Value="Hand" />
                <Setter Property="Margin" Value="5" />
                <Setter Property="HorizontalAlignment" Value="Stretch" />
                <!--<Setter Property="ContextMenu" Value="{DynamicResource SnippetContextMenu}" />-->
                <Setter Property="OverridesDefaultStyle" Value="True" />
                <Setter Property="FocusVisualStyle" Value="{x:Null}" />
                <Setter Property="Foreground" Value="#C8C8C8" />
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type ListBoxItem}">
                            <ContentPresenter VerticalAlignment="Center" Margin="0,0,0,0" />

                            <!--<ControlTemplate.Triggers>
                                <Trigger Property="IsSelected" Value="True">
                                    <Setter TargetName="Border" Property="Background" Value="#20FFFFFF" />
                                    <Setter Property="Foreground" Value="#FFFFFF" />
                                </Trigger>
                            </ControlTemplate.Triggers>-->

                        </ControlTemplate>

                    </Setter.Value>
                </Setter>
            </Style>

        </ResourceDictionary>
    </UserControl.Resources>


    <DockPanel LastChildFill="True" >
        <ListBox ScrollViewer.CanContentScroll="False" Visibility="Visible" 
                 x:Name="lstDb" Margin="3" ItemContainerStyle="{StaticResource ListBoxItemStyle}"   
                 ItemsSource="{Binding Path=SpaceUsages}" />
    </DockPanel>

</UserControl>
